import { ESCesiumViewer } from "@czmSrc/ESCesiumViewer";
import { ESJVector3D } from "earthsdk3";
import { extendClassProps, ReactivePropsToNativePropsAndChanged, reactPositionsSet, track } from "xbsj-base";
import { CzmPolylines } from "@czmSrc/CzmObjects";
import { MultiPointsModifyEditing } from ".";

export class VisibilityModifyEditing extends MultiPointsModifyEditing {
    constructor(czmViewer: ESCesiumViewer) {
        super(czmViewer);
        if (!czmViewer.viewer) return;
        this.loop = false;
        this.middlePointShow = false;
        {
            const update = () => {
                if (!this.positions || this.positions.length < 2) return;
                const origin = [...this.positions[0]] as ESJVector3D;
                origin[2] -= czmViewer.editingHeightOffset ?? 0;
                this.visibilityPositions = this.positions.map(item => {
                    item[2] -= czmViewer.editingHeightOffset ?? 0;
                    return [origin, item];
                })
            }
            update();
            this.ad(this.positionsChanged.don(update));
        }
    }
    public override createPolyline(czmViewer: ESCesiumViewer) {
        const polyline = this.ad(new CzmPolylines(czmViewer));
        polyline.topOrBottom = 'bottom';
        this.ad(track([polyline, 'color'], [this, 'polylineColor']))
        this.ad(track([polyline, 'width'], [this, 'polylineWidth']))
        this.ad(track([polyline, 'show'], [this, 'polylineShow']))
        this.ad(track([polyline, 'arcType'], [this, 'polylineArcType']))
        this.ad(track([polyline, 'loop'], [this, 'loop']));
        this.ad(track([polyline, 'positions'], [this, 'visibilityPositions']));
    }
}
export namespace VisibilityModifyEditing {
    export const createDefaultProps = () => ({
        ...MultiPointsModifyEditing.createDefaultProps(),
        visibilityPositions: reactPositionsSet(undefined),
    })
}
extendClassProps(VisibilityModifyEditing.prototype, VisibilityModifyEditing.createDefaultProps);
export interface VisibilityModifyEditing extends ReactivePropsToNativePropsAndChanged<ReturnType<typeof VisibilityModifyEditing.createDefaultProps>> { }
